<?php

if( !function_exists("get_absolute_template_path")){
	function get_absolute_template_path(){
		$templatePath= get_theme_root()."/".get_template();
		$templatePath= str_replace("\\","/",$templatePath);
		return $templatePath;
	}
}
if( !function_exists("get_local_timeStamp")){
	function get_local_timeStamp($time, $format='Y-m-d H:i:s'){
		$timeStamp = '';
		$epoch= strtotime($time);
		$epoch += 60*60*6; //Bangladesh time offset
		
		$timeStamp= date_i18n($format, $epoch, '');
		return $timeStamp;
	}
}
if( !function_exists("convertNewlineToBRcode")){
	function convertNewlineToBRcode($text){
		return str_replace("\n","<br/>",$text);
	}
}

function buetian_login_logo_url() {
    return get_bloginfo( 'url' );
}
add_filter( 'login_headerurl', 'buetian_login_logo_url' );
function buetian_login_logo_url_title() {
    return "Return to Homepage";
}
add_filter( 'login_headertitle', 'buetian_login_logo_url_title' );


add_theme_support('post-thumbnails');
set_post_thumbnail_size(980,150,true);

/* carried over from 2.7*/
add_action('admin_menu', 'myan_plugin_menu');

function myan_plugin_menu() {
		
	add_menu_page("Mythic- Admin- Options", "Admin || Tools", 'manage_options', 'myan-top-level-handle', 'myan_sublevel_banner_extendedForError' );
	// Add a submenu to the custom top-level menu:

	// Add a submenu to the custom top-level menu:
    add_submenu_page('myan-top-level-handle', "Set banner image", "Banner image", 'manage_categories', 'myan-top-level-handle', 'myan_sublevel_banner');

	// Add a submenu to the custom top-level menu:
    //add_submenu_page('myan-top-level-handle', "Set front page hightlighed post", "Highlighted posts", 'manage_categories', 'myan-sub-hightlighed', 'myan_sublevel_highlighted');
	// Add a submenu to the custom top-level menu:
    //add_submenu_page('myan-top-level-handle', "Set panorama link", "Quote/Notice", 'manage_categories', 'myan-sub-panorama', 'myan_sublevel_panorama');
	// Add a submenu to the custom top-level menu:
    add_submenu_page('myan-top-level-handle', "Import posts", "Import posts", 'edit_posts', 'myan-sub-importPost', 'myan_sublevel_importPost');
	// Add a submenu to the custom top-level menu:
    //add_submenu_page('myan-top-level-handle', "Set youtube link", "Youtube link", 'manage_categories', 'myan-sub-youtube', 'myan_sublevel_youtube');
	// Add a submenu to the custom top-level menu:
    add_submenu_page('myan-top-level-handle', "Message to user", "Message to user", 'edit_posts', 'myan-sub-message-to-user', 'myan_sublevel_message_to_user');
	
}

function myan_sublevel_message_to_user()
{	
	include_once("admin.panel/message_to_user.php");
}

function myan_sublevel_banner_extendedForError()
{
	;
}

function myan_sublevel_youtube()
{
	include_once("admin.panel/youtube.php");
}

function myan_sublevel_importPost()
{
	include_once("admin.panel/importPost.php");
}


function myan_sublevel_highlighted()
{
	include_once("admin.panel/highlighted.php");
}

function myan_sublevel_banner()
{
	include_once("admin.panel/banner.php");
}

// basically for panaorama pic link but replaced with quote to code less
function myan_sublevel_panorama()
{
	include_once("admin.panel/quote.php");
}


function myan_home() {
	echo "<h1>Edit your settings here</h1><br/><br/>";
	
	$templatePath= get_absolute_template_path();
	
	$settings=array();
	
	if( isset($_FILES['uploadedfile']))
	{
		move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $templatePath."/images/".basename($_FILES['uploadedfile']['name']));
		$settings=	 json_decode(file_get_contents($templatePath."/settings.txt"));
		$settings->title_image= $_FILES['uploadedfile']['name'];
		
		file_put_contents($templatePath."/settings.txt", json_encode($settings));
	}
	else
		$settings= json_decode(file_get_contents($templatePath."/settings.txt"));
	
	include_once("admin.panel/banner.php");
}
/*
// Hook for adding admin menus
//add_action('admin_menu', 'mt_add_pages');

// action function for above hook
function mt_add_pages() {
    // Add a new submenu under Settings:
    add_options_page(__('Test Settings','menu-test'), __('Test Settings','menu-test'), 'manage_options', 'testsettings', 'mt_settings_page');

    // Add a new submenu under Tools:
    add_management_page( __('Test Tools','menu-test'), __('Test Tools','menu-test'), 'manage_options', 'testtools', 'mt_tools_page');

    // Add a new top-level menu (ill-advised):
    add_menu_page(__('Test Toplevel','menu-test'), __('Test Toplevel','menu-test'), 'manage_options', 'mt-top-level-handle', 'mt_toplevel_page' );

    // Add a submenu to the custom top-level menu:
    add_submenu_page('mt-top-level-handle', __('Test Sublevel','menu-test'), __('Test Sublevel','menu-test'), 'manage_options', 'sub-page', 'mt_sublevel_page');

    // Add a second submenu to the custom top-level menu:
    add_submenu_page('mt-top-level-handle', __('Test Sublevel 2','menu-test'), __('Test Sublevel 2','menu-test'), 'manage_options', 'sub-page2', 'mt_sublevel_page2');
}

// mt_settings_page() displays the page content for the Test settings submenu
function mt_settings_page() {
    echo "<h2>" . __( 'Test Settings', 'menu-test' ) . "</h2>";
}

// mt_tools_page() displays the page content for the Test Tools submenu
function mt_tools_page() {
    echo "<h2>" . __( 'Test Tools', 'menu-test' ) . "</h2>";
}

// mt_toplevel_page() displays the page content for the custom Test Toplevel menu
function mt_toplevel_page() {
    echo "<h2>" . __( 'Test Toplevel', 'menu-test' ) . "</h2>";
}

// mt_sublevel_page() displays the page content for the first submenu
// of the custom Test Toplevel menu
function mt_sublevel_page() {
    echo "<h2>" . __( 'Test Sublevel', 'menu-test' ) . "</h2>";
}

// mt_sublevel_page2() displays the page content for the second submenu
// of the custom Test Toplevel menu
function mt_sublevel_page2() {
    echo "<h2>" . __( 'Test Sublevel2', 'menu-test' ) . "</h2>";
}
*/

?>